package net.zisen.cloud.core.security.realm;

import net.zisen.cloud.core.security.matcher.JWTCredentialsMatcher;
import net.zisen.cloud.core.security.token.JwtToken;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.CredentialsMatcher;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.cache.CacheManager;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.stereotype.Component;

/**
 * @author tim/278002989@qq.com
 * @Classname JwtShiroToken
 * @Description TODO
 * @Date 2019-03-31 23:36
 */
@Component("authorizer")
public class ShiroJwtRealm extends AuthorizingRealm {
    public ShiroJwtRealm() {
        this.setCredentialsMatcher(new JWTCredentialsMatcher());
    }

    public ShiroJwtRealm(CacheManager cacheManager) {
        super(cacheManager);
        this.setCredentialsMatcher(new JWTCredentialsMatcher());
    }

    public ShiroJwtRealm(CredentialsMatcher matcher) {
        super(matcher);
        this.setCredentialsMatcher(new JWTCredentialsMatcher());
    }

    public ShiroJwtRealm(CacheManager cacheManager, CredentialsMatcher matcher) {
        super(cacheManager, matcher);
        this.setCredentialsMatcher(new JWTCredentialsMatcher());
    }

    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        return null;
    }

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) {
        return null;
    }

    @Override
    public boolean supports(AuthenticationToken token) {
        return token instanceof JwtToken;
    }


}
